<!doctype html>



  


<html class="theme-next pisces use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Android,tools," />





  <link rel="alternate" href="/atom.xml" title="GrantonZhuang's Blog" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="在开发过程中，随着项目扩大，经验累积，会产生出来一些类似 SDK 的代码库，如果是个人的代码库，可以放在 maven 的远程仓库上，如果不想公开，则可以搭建一个私有的仓库。
本文重点在于记录使用 nexus 搭建私有的 Android 仓库的过程。">
<meta property="og:type" content="article">
<meta property="og:title" content="使用nexus搭建maven仓库">
<meta property="og:url" content="https://grantonzhuang.github.io/2016/05/26/使用nexus搭建maven仓库/index.html">
<meta property="og:site_name" content="GrantonZhuang's Blog">
<meta property="og:description" content="在开发过程中，随着项目扩大，经验累积，会产生出来一些类似 SDK 的代码库，如果是个人的代码库，可以放在 maven 的远程仓库上，如果不想公开，则可以搭建一个私有的仓库。
本文重点在于记录使用 nexus 搭建私有的 Android 仓库的过程。">
<meta property="og:updated_time" content="2016-09-21T11:38:35.031Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="使用nexus搭建maven仓库">
<meta name="twitter:description" content="在开发过程中，随着项目扩大，经验累积，会产生出来一些类似 SDK 的代码库，如果是个人的代码库，可以放在 maven 的远程仓库上，如果不想公开，则可以搭建一个私有的仓库。
本文重点在于记录使用 nexus 搭建私有的 Android 仓库的过程。">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="https://grantonzhuang.github.io/2016/05/26/使用nexus搭建maven仓库/"/>

  <title> 使用nexus搭建maven仓库 | GrantonZhuang's Blog </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">GrantonZhuang's Blog</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle"></p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/index.html" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/index.html" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/index.html" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                使用nexus搭建maven仓库
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-05-26T10:56:47+08:00" content="2016-05-26">
              2016-05-26
            </time>
          </span>

          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>在开发过程中，随着项目扩大，经验累积，会产生出来一些类似 SDK 的代码库，如果是个人的代码库，可以放在 maven 的远程仓库上，如果不想公开，则可以搭建一个私有的仓库。</p>
<p>本文重点在于记录使用 nexus 搭建私有的 Android 仓库的过程。</p>
<a id="more"></a>
<h2 id="安装-nexus"><a href="#安装-nexus" class="headerlink" title="安装 nexus"></a>安装 nexus</h2><p><a href="http://www.sonatype.com/download-oss-sonatype?__hssc=31049440.1.1464285275567&amp;__hstc=31049440.7eb382bf08d5a761794251f20f477696.1463155219549.1464274438507.1464285275567.5&amp;__hsfp=4122800578&amp;hsCtaTracking=43e2beb1-4cb4-42e4-b2d8-9bb4edf0493b%7C7c6988c8-ca35-42d0-b585-ae5147f27d5b" target="_blank" rel="external">下载 nexus</a></p>
<p>安装之后执行对应的可执行文件即可。</p>
<blockquote>
<p>安装过程中需要指定程序占内存的大小，如果内存设置过大，会出现服务跑不起来的情况。</p>
</blockquote>
<h2 id="建立一个仓库"><a href="#建立一个仓库" class="headerlink" title="建立一个仓库"></a>建立一个仓库</h2><p>在 web 管理界面 <a href="http://ip:port" target="_blank" rel="external">http://ip:port</a> 新建一个 maven2(hosted) 的仓库</p>
<blockquote>
<p>IP 一般是 localhost，当然远程的话，就是远程服务器的 IP，实际上，IP 为远程 IP 才会显得比较有意义。<br>port 一般是默认的 8081</p>
</blockquote>
<h2 id="使用-Android-Studio-上传代码库"><a href="#使用-Android-Studio-上传代码库" class="headerlink" title="使用 Android Studio 上传代码库"></a>使用 Android Studio 上传代码库</h2><p>编辑 lib module 的 <code>build.gradle</code> 的文件：</p>
<figure class="highlight gradle"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div></pre></td><td class="code"><pre><div class="line">apply plugin: <span class="string">'com.android.library'</span></div><div class="line">apply plugin: <span class="string">'maven-publish'</span></div><div class="line">apply plugin: <span class="string">'maven'</span></div><div class="line"></div><div class="line">uploadArchives &#123;</div><div class="line">    <span class="keyword">repositories</span> &#123;</div><div class="line">        Properties properties = <span class="keyword">new</span> Properties()</div><div class="line">        properties.load(<span class="keyword">project</span>.rootProject.<span class="keyword">file</span>(<span class="string">'local.properties'</span>).newDataInputStream())</div><div class="line">        <span class="keyword">def</span> RELEASE_REPOSITORY_URL = properties.getProperty(<span class="string">'RELEASE_REPOSITORY_URL'</span>)</div><div class="line">        <span class="keyword">def</span> nexusUsername = properties.getProperty(<span class="string">'nexusUsername'</span>)</div><div class="line">        <span class="keyword">def</span> nexusPassword = properties.getProperty(<span class="string">'nexusPassword'</span>)</div><div class="line">        mavenDeployer &#123;</div><div class="line">            repository(url: RELEASE_REPOSITORY_URL) &#123;</div><div class="line">                authentication(userName: nexusUsername, password: nexusPassword)</div><div class="line">            &#125;</div><div class="line"></div><div class="line">            pom.<span class="keyword">project</span> &#123;</div><div class="line">                name PROJ_GROUP_ID</div><div class="line">                packaging POM_PACKAGING</div><div class="line">                groupId PROJ_GROUP_ID</div><div class="line">                artifactId PROJ_ARTIFACT</div><div class="line">                version PKG_VERSION</div><div class="line">            &#125;</div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>在项目的根目录，编辑 <code>gradle.properties</code> 文件</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">PKG_VERSION=1.0.0</div><div class="line">PROJ_GROUP_ID=repoName</div><div class="line">PROJ_ARTIFACT=libId</div><div class="line">POM_PACKAGING=aar</div></pre></td></tr></table></figure>
<p>敏感信息放在版本控制之外的 <code>local.properties</code> 中</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">nexusUsername=username</div><div class="line">nexusPassword=password</div><div class="line">RELEASE_REPOSITORY_URL=http://ip:port/repository/repoName/</div></pre></td></tr></table></figure>
<h3 id="对照表"><a href="#对照表" class="headerlink" title="对照表"></a>对照表</h3><table>
<thead>
<tr>
<th style="text-align:center">key</th>
<th style="text-align:center">desc</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">nexusUsername</td>
<td style="text-align:center">即 web 管理界面的用户名</td>
</tr>
<tr>
<td style="text-align:center">nexusPassword</td>
<td style="text-align:center">即 web 管理界面的密码</td>
</tr>
<tr>
<td style="text-align:center">RELEASE_REPOSITORY_URL</td>
<td style="text-align:center">仓库的 URL</td>
</tr>
<tr>
<td style="text-align:center">PKG_VERSION</td>
<td style="text-align:center">版本号</td>
</tr>
<tr>
<td style="text-align:center">PROJ_GROUP_ID</td>
<td style="text-align:center">仓库名称</td>
</tr>
<tr>
<td style="text-align:center">PROJ_ARTIFACT</td>
<td style="text-align:center">组件 ID （一个仓库可以有多个组件）</td>
</tr>
<tr>
<td style="text-align:center">POM_PACKAGING</td>
<td style="text-align:center">打包方式</td>
</tr>
</tbody>
</table>
<p>在 bash 中执行 gradle 的任务</p>
<blockquote>
<p>每一次 upload，gradle文件中的 version 的值都需要改变</p>
</blockquote>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">gradle uploadArchives</div></pre></td></tr></table></figure>
<h2 id="在项目中对该仓库进行依赖"><a href="#在项目中对该仓库进行依赖" class="headerlink" title="在项目中对该仓库进行依赖"></a>在项目中对该仓库进行依赖</h2><p>app-level 的 <code>build.gradle</code>:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">allprojects &#123;</div><div class="line">    repositories &#123;</div><div class="line">        jcenter()</div><div class="line"></div><div class="line"></div><div class="line">        maven &#123;</div><div class="line">            url &apos;RELEASE_REPOSITORY_URL&apos;</div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>module-level 的 <code>build.gradle</code>:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">dependencies &#123;</div><div class="line">    compile &apos;groupID:ArtifactID:versionCode&apos;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Android/" rel="tag">#Android</a>
          
            <a href="/tags/tools/" rel="tag">#tools</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/05/22/Android-动态加载入门/" rel="next" title="Android-动态加载入门">
                <i class="fa fa-chevron-left"></i> Android-动态加载入门
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/05/28/Android-动态加载进阶-代理Activity/" rel="prev" title="Android-动态加载进阶-代理Activity和提供资源文件">
                Android-动态加载进阶-代理Activity和提供资源文件 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="http://ww1.sinaimg.cn/mw690/6e8939a6gw1f3g1u1mc6lj20hs0hsmxf.jpg"
               alt="Granton Zhuang" />
          <p class="site-author-name" itemprop="name">Granton Zhuang</p>
          <p class="site-description motion-element" itemprop="description"></p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives/index.html">
              <span class="site-state-item-count">26</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">11</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#安装-nexus"><span class="nav-number">1.</span> <span class="nav-text">安装 nexus</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#建立一个仓库"><span class="nav-number">2.</span> <span class="nav-text">建立一个仓库</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#使用-Android-Studio-上传代码库"><span class="nav-number">3.</span> <span class="nav-text">使用 Android Studio 上传代码库</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#对照表"><span class="nav-number">3.1.</span> <span class="nav-text">对照表</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#在项目中对该仓库进行依赖"><span class="nav-number">4.</span> <span class="nav-text">在项目中对该仓库进行依赖</span></a></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Granton Zhuang</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>

        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.0.1"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  



  




  
  

  

  

  

</body>
</html>
